local kunfen = fk.CreateSkill {

  name = "joysp__kunfen",

  tags = {  },

}



kunfen:addEffect(fk.EventPhaseStart, {
  name = "joysp__kunfen",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(kunfen.name) and player.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:loseHp(player, 1, kunfen.name)
    if not player.dead then player:drawCards(2, kunfen.name) end
    if not player:prohibitUse(Fk:cloneCard("fire_attack")) then
      local Fire = Fk:cloneCard "fire_attack"
      local targets = {}
      for _, p in ipairs(player.room:getAlivePlayers()) do
        if not p:isKongcheng() then
          table.insert(targets,p.id)
        end
      end
      if #targets == 0 then return end
      local tos = room:askForChoosePlayers(player, targets, 1,1, "#joy__kunfen-choose", kunfen.name, true)
      if #tos > 0 then
        local Fire_attack = Fk:cloneCard "fire_attack"
        Fire_attack.skillName = kunfen.name
        room:useCard {
          from = target.id,
          tos = table.map(tos, function(pid) return { pid } end),
          card = Fire_attack,
          extraUse = true,
        }
      end
    end
  end,
})

return kunfen